using System;
using BitMango.Diagnostics;
using BMCommon;
using UnityEngine;

public class MessageBlock : MonoBehaviour
{
	public string Text
	{
		get
		{
			return this.message.GetComponent<TextMesh>().text;
		}
		set
		{
			this.message.GetComponent<TextMesh>().text = value;
		}
	}

	public void Show(Camera cam)
	{
		base.transform.parent = cam.transform;
		this.plane.FadeIn(0.3f, this.fadeTarget, null);
		this.circle.Round(28, 60f, false);
		base.transform.localPosition = new Vector3(0f, 0f, 1f);
		this.UpdateScale(cam);
		tk2dCamera component = cam.GetComponent<tk2dCamera>();
		if (component != null)
		{
			tk2dCameraSettings tk2dCameraSettings = (!(component.InheritConfig == null)) ? component.InheritConfig.CameraSettings : component.CameraSettings;
			if (tk2dCameraSettings.orthographicOrigin == tk2dCameraSettings.OrthographicOrigin.BottomLeft)
			{
				Rect screenExtents = component.ScreenExtents;
				base.transform.localPosition = new Vector3(screenExtents.x + screenExtents.width * 0.5f, screenExtents.y + screenExtents.height * 0.5f, 1f);
			}
		}
	}

	public void Hide()
	{
		this.plane.FadeOut(0.3f, false, delegate
		{
			base.gameObject.SetActive(false);
		});
	}

	public void SetPlaneColor(Color color)
	{
		this.plane.GetComponent<Renderer>().material.color = color;
	}

	private void UpdateScale(Camera cam)
	{
		Debugger.Assert(cam != null);
		Vector3 cameraScale = this.GetCameraScale(cam);
		this.circle.transform.localScale = Vector3.one * cameraScale.x;
		this.message.transform.localScale = Vector3.one * (cameraScale.x * 0.0225000568f);
		this.message.transform.localPosition = new Vector3(0f, -0.15f * cameraScale.x, 1f);
		this.plane.transform.localScale = cameraScale;
	}

	private Vector3 GetCameraScale(Camera cam)
	{
		tk2dCamera component = cam.GetComponent<tk2dCamera>();
		if (component != null)
		{
			return new Vector3(component.ScreenExtents.width, component.ScreenExtents.height, 1f);
		}
		float num = cam.orthographicSize * 2f;
		return new Vector3(num * cam.aspect, num, 1f);
	}

	public GameObject circle;

	public GameObject message;

	public GameObject plane;

	public float fadeTarget = 0.5f;
}
